/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PCR;

import Enums.ProjectType;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author marwa
 */
public class NewmRNA extends javax.swing.JInternalFrame {

    /**
     * Creates new form NewmRNA
     */
    String ImageTitle;
    String sampleNumber;
    WorkArea obj;
    Toolbox toolbox;
    int hight;
    int width;

    public NewmRNA() {
        initComponents();
        MainFrame frm = (MainFrame) java.awt.Window.getWindows()[0];
        hight = (frm.getHeight() / 2) - (this.getHeight());
        width = frm.getWidth() / 2 - (this.getWidth() / 2);

        this.setLocation(width, hight);
        this.getRootPane().setDefaultButton(createButton);
        obj = new WorkArea(ImageTitle, true, "MRNA");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        mrnaTitle = new javax.swing.JTextField();
        sampleComboBox = new javax.swing.JComboBox();
        createButton = new javax.swing.JButton();
        cancelButto = new javax.swing.JButton();

        setClosable(true);
        setTitle("New m-RNA");

        jLabel1.setText("Title:");

        jLabel2.setText("Samples:");

        mrnaTitle.setText("Untitled");

        sampleComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "4 Samples", "8 Samples", "16 Samples" }));

        createButton.setText("Create");
        createButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createButtonActionPerformed(evt);
            }
        });

        cancelButto.setText("Cancel");
        cancelButto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addComponent(createButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 111, Short.MAX_VALUE)
                .addComponent(cancelButto)
                .addGap(89, 89, 89))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(38, 38, 38)
                        .addComponent(mrnaTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sampleComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(61, 61, 61))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(71, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(mrnaTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(sampleComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(53, 53, 53)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(createButton)
                    .addComponent(cancelButto))
                .addGap(64, 64, 64))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtoActionPerformed

        this.setVisible(false);
    }//GEN-LAST:event_cancelButtoActionPerformed
    private String CheckTitle(String text) {
        if (text.equals("Untitled") || text.equals("")) {
            return "Untitled";
        } else {
            return text;
        }

    }

    private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed

        ImageTitle = CheckTitle(mrnaTitle.getText());
        sampleNumber = (String) sampleComboBox.getSelectedItem();

        MainFrame test = (MainFrame) this.getParent().getParent().getParent().getParent().getParent();
        test.getDualButton().setEnabled(true);
        
        obj.setTitle(ImageTitle);
        obj.wheelBandsDrawer(Integer.parseInt(sampleNumber.split(" ")[0]));
        obj.setSampleSize(Integer.parseInt(sampleNumber.split(" ")[0]));
        obj.setVisible(true);
        obj.setSize(800, 600);
        obj.setLocation(220, 10);
        obj.setProjectType(ProjectType.MRNA);
        obj.toFront();
        obj.getBandsPanel().setSampleType(sampleNumber);
        obj.grabFocus();
        test.setSelectedWorkArea(obj);
        
        super.getDesktopPane().add(obj);
        try {
            obj.setSelected(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(NewPCR.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.setVisible(false);

        toolbox = test.getToolbox();
        toolbox.initializeTools(ProjectType.MRNA);

        test.getPositioningToolbar().setVisible(true);
    }//GEN-LAST:event_createButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButto;
    private javax.swing.JButton createButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField mrnaTitle;
    private javax.swing.JComboBox sampleComboBox;
    // End of variables declaration//GEN-END:variables
}
